package com.qili.service.base.impl;

import com.qili.base.mapper.BaseMapper;
import com.qili.base.service.impl.BaseServiceImpl;
import com.qili.entity.base.BaseStageZx;
import com.qili.entity.base.dto.BaseStageMileDTO;
import com.qili.mapper.base.BaseStageMapper;
import com.qili.mapper.base.BaseStageZxMapper;
import com.qili.service.base.BaseStageService;
import com.qili.service.base.BaseStageZxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhaoyongke
 * @date 2020/11/3
 * @description 基础阶段
 */
@Service
public class BaseStageServiceZxImpl extends BaseServiceImpl<BaseStageZx,String> implements BaseStageZxService {

    @Autowired
    private BaseStageZxMapper BaseStageMapper;
    @Override
    public BaseMapper<BaseStageZx, String> getMappser() {
        return BaseStageMapper;
    }

    /**
    * @Author:Zhangshuo
    * @Description:
    * @param baseStageDto
    * @Date:19:17 2020/11/19
    */
    @Override
    public List<BaseStageMileDTO> selectStageMileByProjectType(BaseStageMileDTO baseStageDto) {
        return BaseStageMapper.selectStageMileByProjectType(baseStageDto);
    }
    /**
    * @Author:Zhangshuo
    * @Description:
    * @param id
    * @Date:19:17 2020/11/19
    */
    @Override
    public int delStage(String id) {
        return BaseStageMapper.delStage(id);
    }
    /**
    * @Author:Zhangshuo
    * @Description:
    * @param baseStage
    * @Date:19:17 2020/11/19
    */
    @Override
    public int updateStage(BaseStageZx baseStage) {
        return BaseStageMapper.updateStage(baseStage);
    }
    /**
    * @Author:Zhangshuo
    * @Description:
    * @param baseStage
    * @Date:19:17 2020/11/19
    */
    @Override
    public int addStage(BaseStageZx baseStage) {
        return BaseStageMapper.addStage(baseStage);
    }

    @Override
    public List<BaseStageZx> selectBaseStageListByProjectTypeNo(String projectTypeNo,String dictTypeCode) {
        Map paraMap = new HashMap();
        paraMap.put("projectTypeNo",projectTypeNo);
        paraMap.put("badtTypeCode",dictTypeCode);
        return BaseStageMapper.selectBaseStageListByProjectTypeNo(paraMap);
    }

    @Override
    public boolean ifExited(BaseStageZx baseStage) {
        BaseStageZx selectBaseStage = new BaseStageZx();
        selectBaseStage.setStageNo(baseStage.getStageNo());
        selectBaseStage.setProjectTypeNo(baseStage.getProjectTypeNo());
        return BaseStageMapper.selectOne(selectBaseStage) != null;
    }

    @Override
    public boolean checkCanEdit(BaseStageZx baseStage) {
        BaseStageZx oldStage = BaseStageMapper.selectByPrimaryKey(baseStage);
        if(!oldStage.getStageNo().equals(baseStage.getStageNo())){
            return !ifExited(baseStage);
        }
        return true;
    }
}
